﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;

namespace ABELGX
{
    public class InfoMotor: CarInfo
    {
        public Sensor Acc { get; set; } = new Sensor(new SensorSet("发动机油门", "%", 1, "f0"));
        public Sensor Rpm { get; set; } = new Sensor(new SensorSet("发动机转速", "RPM", 1, "f0"));
        public Sensor OilLevel { get; set; } = new Sensor(new SensorSet("燃油液位", "%", 1, "f0"));
        public Sensor OilTemperature { get; set; } = new Sensor(new SensorSet("液压油温", "℃", 1, "f0"));
        public Sensor WaterTemperature { get; set; } = new Sensor(new SensorSet("发动机水温", "℃", 1, -50,"f0"));
        public Sensor AirTemperature { get; set; } = new Sensor(new SensorSet("环境温度", "℃", 1, -50, "f0"));
        public Sensor Hours { get; set; } = new Sensor(new SensorSet("工作小时数", "H", 1, "f0"));
        public InfoMotor(params byte[] func) : base(func)
        {
            
        }
        public override void ProcessData(byte[] data, int start)
        {
            int i = start + 1;
            switch (data[start])
            {
                case INFO_MOTOR:
                    Acc.Value = BitConverter.ToUInt16(data, i);
                    i += 2;
                    Rpm.Value = BitConverter.ToUInt16(data, i);
                    i += 2;
                    OilLevel.Value = (data[i] << 8) | data[i + 1];
                    i += 2;
                    OilTemperature.Value = data[i++];
                    WaterTemperature.Value = BitConverter.ToInt16(data, i);
                    i += 2;
                    AirTemperature.Value = BitConverter.ToInt16(data, i);
                    i += 2;
                    Hours.Value = BitConverter.ToInt32(data, i);
                    i += 4;
                    break;
                default:
                    break;
            }
        }

        public override void InitData()
        {
            Acc.Value = 0;
            Rpm.Value = 0;
            OilLevel.Value = 0;
            AirTemperature.Value = 0;
            OilTemperature.Value = 0;
            WaterTemperature.Value = 0;
            Hours.Value = 0;
        }
    }
}
